package com.scaffold.commons.spring;

import java.util.Properties;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;

import com.scaffold.commons.config.SysConfig;

/**
 * 自动设置locations，locations通过{@link SysConfig SysConfig.instance.getConfigPath()}获取
 * @author wangjg
 *
 */
public class MyPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

	public MyPropertyPlaceholderConfigurer() {
		String configPath = SysConfig.selectedPath;
		this.setLocation(new ClassPathResource(configPath));
		
		//default value
		this.setSystemPropertiesMode(SYSTEM_PROPERTIES_MODE_OVERRIDE);
		this.setIgnoreResourceNotFound(true);
		this.setIgnoreUnresolvablePlaceholders(true);
	}
	
	protected String resolvePlaceholder(String placeholder, Properties props) {
		return super.resolvePlaceholder(placeholder, props);
	}
	
}

/*
 * <bean class="com.scaffold.commons.config.MyPropertyPlaceholderConfigurer" />
 */